class AccountInfo {
    constructor(db) {
      this.db = db;
    }
  
    async createTable() {
      const sql = `
        CREATE TABLE IF NOT EXISTS account_info (
          id INTEGER NOT NULL PRIMARY KEY,
          google_account VARCHAR NOT NULL,
          google_password VARCHAR NOT NULL,
          x_account VARCHAR NOT NULL,
          x_password VARCHAR NOT NULL,
          dc_account VARCHAR NOT NULL,
          dc_password VARCHAR NOT NULL,
          wallet_address VARCHAR NOT NULL,
          wallet_private_key VARCHAR NOT NULL,
          wallet_words_key VARCHAR NOT NULL,
          sol_address VARCHAR NOT NULL,
          sol_private_key VARCHAR NOT NULL,
          sol_words_key VARCHAR NOT NULL,
          tel_address VARCHAR NOT NULL,
          tel_password VARCHAR NOT NULL,
          sol_push_address VARCHAR NOT NULL
        );
      `;
      await this.db.query(sql);
      console.log('AccountInfo table created.');
    }
  
    async insert(accountData) {
      const sql = `
        INSERT INTO account_info (
          google_account, google_password, x_account, x_password,
          dc_account, dc_password, wallet_address, wallet_private_key, wallet_words_key,
          sol_address, sol_private_key, sol_words_key, tel_address, tel_password, sol_push_address
        ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
      `;
      const accountId = await this.db.insert(sql, Object.values(accountData));
      return accountId;
    }
  
    async getById(id) {
      const sql = 'SELECT * FROM account_info WHERE id = ?';
      const accounts = await this.db.query(sql, [id]);
      return accounts[0];
    }
  
    async getAll() {
      const sql = 'SELECT * FROM account_info';
      return await this.db.query(sql);
    }
  
    async update(id, accountData) {
      const sql = `
        UPDATE account_info SET 
          google_account = ?, google_password = ?, x_account = ?, x_password = ?,
          dc_account = ?, dc_password = ?, wallet_address = ?, wallet_private_key = ?, wallet_words_key = ?,
          sol_address = ?, sol_private_key = ?, sol_words_key = ?, tel_address = ?, tel_password = ?, sol_push_address = ?
        WHERE id = ?
      `;
      const changes = await this.db.update(sql, [...Object.values(accountData), id]);
      return changes;
    }
  
    async delete(id) {
      const sql = 'DELETE FROM account_info WHERE id = ?';
      const changes = await this.db.delete(sql, [id]);
      return changes;
    }

    async get_by_solana_address(sol_address) {
        const sql = 'select * FROM account_info WHERE sol_address = ?';
        const accounts = await this.db.query(sql, [sol_address]);
       return accounts[0];
      }


  }
  
  module.exports = AccountInfo;